package Using_Custom_Class;

/**
 * @author wly
 * @version V1.0.0
 * @date 2023/1/21 10:27
 */
public class LinearSearch {

    private LinearSearch(){}

    public static <E> int search(E[] data, E target){
        for (int i = 0; i < data.length; i++) {
            if (data[i].equals(target)){
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        Student[] students = {new Student("Alice"),
                              new Student("Bobo"),
                              new Student("Charles")};
        Student bobo = new Student("Bobo");
        int res3 = LinearSearch.search(students, bobo);
        System.out.println("res = " + res3);
    }
}
